package com.linciping.gradle.test

import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup


object FragmentInjector {

    /**
     * 将fragment的名称注入到fragment的view中
     *
     * @param obj                fragment对象
     * @param parentView         fragment根视图
     * @param savedInstanceState
     */
    @JvmStatic
    fun injectorFragment(obj: Any, parentView: View, savedInstanceState: Bundle?) {
        try {
            if (!InjectorUtils.isFragment(obj)) {
                return
            }
            val fragmentName = obj.javaClass.name
            parentView.setTag(R.id.inject_fragment_name, fragmentName)
            if (parentView is ViewGroup) {
                //遍历所有控件，注入fragment类名
                InjectorUtils.recursiveChildView(parentView, fragmentName)
            }
        } catch (ex: Exception) {
            Log.e("FragmentInjector", ex.message!!)
        }
    }
}